//
//  HomeTownControl.m
//  FreeTime
//
//  Created by  on 16/8/26.
//  Copyright © 2016年 SRDZ.com. All rights reserved.
//

#import "HomeTownControl.h"
#import "Header.h"
#import "HomeTownCell.h"
@interface HomeTownControl ()
{
    NSArray * cityArr;
}

@end

@implementation HomeTownControl

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadOriData];
    [self setupUI];
    [self setupNav];
    
    
}
#pragma mark -- selfStyle --

- (void)setupUI{

    UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, WindowWidth, 40);
    [btn addTarget:self action:@selector(clickBtn) forControlEvents:UIControlEventTouchUpInside];
    UILabel * titleLbl = [ReduceCode creatLabelWithFrame:CGRectMake((WindowWidth-115)/2, 0, 100, 40) title:@"创造自己的家乡" titleColor:[ImageUtil colorWithRgb:0x666666] font:14 textAlignment:1];
    [btn addSubview:titleLbl];
    UIImageView * img1 = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(titleLbl.frame)+5, 15, 10, 10)];
    img1.image = [UIImage imageNamed:@"bianji"];
    [btn addSubview:img1];
    [ToolUtil createLine:39 superView:btn lift:10 width:WindowWidth-20 hight:1 color:[ImageUtil colorWithRgb:0xb3b3b3]];

    [self.view addSubview:btn];
    
    self.tableView.frame = CGRectMake(0, 40, WindowWidth, WindowHeight-40-64);
    [self.tableView registerClass:[HomeTownCell class] forCellReuseIdentifier:@"HomeTownCell"];
}
- (void)loadOriData{
    cityArr = @[@"北京",@"上海",@"天津",@"重庆",@"安徽",@"福建",@"甘肃",@"广东",@"贵州",@"河北",@"黑龙江",@"河南",@"湖北",@"湖南",@"吉林",@"江西",@"江苏"];
}

#pragma mark tableViewMethord
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return cityArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 35;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellIdentifier = @"HomeTownCell";
    HomeTownCell * cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    cell.titleLbl.text = cityArr[indexPath.row];
//    if (indexPath.row == 0) {
//        cell.chooseImg.image = [UIImage imageNamed:@"townChoose"];
//    }
    cell.tag = 100+indexPath.row;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSArray * cellArr = [tableView visibleCells];
    HomeTownCell * cell = [tableView cellForRowAtIndexPath:indexPath];
//    for (HomeTownCell * cell in cellArr) {
//        if (cell.tag-100 == indexPath.row) {
            cell.chooseImg.image = [UIImage imageNamed:@"townChoose"];
//        }else{
//            cell.chooseImg.image = [UIImage imageNamed:@""];
//
//        }
//    }
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{
    HomeTownCell * cell = [tableView cellForRowAtIndexPath:indexPath];
   cell.chooseImg.image = [UIImage imageNamed:@""];
}
#pragma mark -- 响应事件 --
- (void)clickBtn{
    
}

@end
